cmake_minimum_required(VERSION 3.1.3)

project(gumballs_ya_xue LANGUAGES C CXX)

# 使能 C++11
# Enable C++11
set(CMAKE_CXX_STANDARD 11)


string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_DIR)
set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release/${BUILD_DIR})
set(LIBRARY_OUTPUT_PATH    ${OUTPUT_DIR})
set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})


# 方便修改全局变量
# Convenient to modify global variables
function(update_cached name value)
    set("${name}" "${value}" CACHE INTERNAL "*** Internal ***" FORCE)
endfunction()

function(update_cached_list name)
    set(_tmp_list "${${name}}")
    list(APPEND _tmp_list "${ARGN}")
    list(REMOVE_DUPLICATES _tmp_list)
    update_cached(${name} "${_tmp_list}")
endfunction()

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK    ccache)
endif()

file(GLOB SRC_LIST ./*.cpp ./*.h)

set(COMPILE_DEFINITIONS ${MK_COMPILE_DEFINITIONS})

add_executable(gumballs_ya_xue ${SRC_LIST})

target_compile_definitions(gumballs_ya_xue
        PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(gumballs_ya_xue
        PRIVATE ${COMPILE_OPTIONS_DEFAULT})

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(gumballs_ya_xue -Wl,--start-group ${MK_LINK_LIBRARIES} -Wl,--end-group)
else()
    target_link_libraries(gumballs_ya_xue ${MK_LINK_LIBRARIES})
endif()
